/*
 * Created on Sat Sep 16 2017
 * @flow
 * Copyright (c) 2017 jianglinjie
 */
'use strict';

import NetRequest from './NetRequest';
import * as HttpMethod from '../constants/HttpMethod';
import * as ResponseType from '../constants/ResponseType';

// export type RNFileInfo = {
//   uri: string,
//   fileName: string,
//   type: string,
// };

export class UploadFileRequest extends NetRequest {
  constructor(url: string, 
    urlParam: Object, 
    bodyParams: Object, 
    uploadFiles: Array<UploadFile>, 
    responseType = ResponseType.JSON_TYPE) {
    let formData = new FormData();

    for (let key of Object.keys(bodyParams)) {
      formData.append(key, bodyParams[key]);
    }

    for (let file of uploadFiles) {
      if (file.fileInfo) {
        formData.append(file.key, file.fileInfo);
      }
    }

    super(url, 
      urlParam, 
      formData, 
      {}, 
      HttpMethod.POST, 
      responseType);
  }
}

export class UploadFile {
  key: string;
  fileInfo: any;

  constructor(key: string, fileInfo: any) {
    this.key = key;
    this.fileInfo = fileInfo;
  }
}